package com.tank.demo.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.awt.*;
import java.awt.image.BufferedImage;

@Data
@NoArgsConstructor
//@AllArgsConstructor
@ToString
public class ImageUtils {
    public static BufferedImage rotateImage(final BufferedImage bufferedImage,final Integer degree){
        int w = bufferedImage.getWidth();
        int h = bufferedImage.getHeight();
        int type = bufferedImage.getType();
        BufferedImage img;
        Graphics2D graphics2D;
        (graphics2D = (img = new BufferedImage(w,h,type)).createGraphics())
                .setRenderingHint(
                RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2D.rotate(Math.toRadians(degree), w / 2, h / 2);
        graphics2D.drawImage(bufferedImage,0,0,null);
        graphics2D.dispose();
        return img;
    }
}
